<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="js/1.4.8/angular.js"></script>
    <script src="js/1.4.8/angular-route.js"></script>
    <style type="text/css">
        body{
            font-size: 1.5em;
        }
        .div{
            background-color: #2a6496;
            width: 780px;
            padding: 8px;
            color: #fff;
        }
    </style>
</head>
<body>
    <div class="div" ng-controller="myCtrl">
        <span>{{stu.name}}</span>
        <span>{{stu.sex}}</span>
        <span>{{stu.score}}</span>
        <br>
        ===========factory自定义服务============
        <div>
            <span>{{str('Fuck！')}}</span>
            <br>
            <span>{{show(1)}}</span>
        </div>
    </div>
    <script type="application/javascript">
        var app = angular.module("app",[]);
        // 使用factory方法自定义服务可以返回一个能被注入对象的数组或函数，
        // 该函数本身在服务实例化时被调用
        // 输出对象
        app.factory("outData",function () {
            var data = {
                name:'江俊',
                sex:'男',
                score:'100'
            };
            return data;
        });
        // 输出json格式的函数（key-value形式）
        app.factory("outFun",function () {
            return{
                str:function (t) {
                    return "来源于自定义服务:" + t;
                }
            }
        });
        // 输出数组
        app.factory("outArr",function () {
            return ["张三","李四","王五"];
        });

        app.controller("myCtrl",["$scope","outData","outFun","outArr",function ($scope,outData,outFun,outArr) {
            $scope.stu = outData;
            $scope.str = function (t) {
                return outFun.str(t);
            };
            $scope.show = function (index) {
                return outArr[index];
            }
        }]);
    </script>
</body>
</html>